<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <el-form :model="where" label-width="96px" class="ele-form-search" @keyup.enter.native="reload"
        @submit.native.prevent>
        <el-row :gutter="15">


          <el-col :lg="4" :md="4">
            <el-form-item label="订单状态">
              <el-select clearable v-model="where.status" placeholder="请选择" class="ele-fluid">
                <el-option label="已支付" value="1" />
                <el-option label="未支付" value="0" />

              </el-select>

            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="4">
            <el-form-item label="用户手机号:">
              <el-input clearable v-model="where.mobile" placeholder="用户手机号" />
            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="4">

            <el-form-item label="日期:" prop="add_time">
              <el-date-picker type="date" clearable v-model="where.add_time" placeholder="请输入结束时间" />

            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="6">
            <el-date-picker type="date" clearable v-model="where.end_time" placeholder="请输入结束时间" />


          </el-col>
          <el-col :lg="6" :md="12">
            <div class="ele-form-actions">
              <el-button type="primary" icon="el-icon-search" class="ele-btn-icon" @click="reload">查询
              </el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <!-- 数据表格 -->
      <ele-pro-table ref="table" :where="where" :datasource="url" :columns="columns" :selection.sync="selection"
        height="calc(100vh - 315px)">
        <!-- 表头工具栏 -->
        <template slot="toolbar">

          <el-button size="small" type="success" icon="el-icon-download" class="ele-btn-icon" @click="exportExcel"
            v-if="permission.includes('sys:order:export')">导出
          </el-button>
        </template>


        <!-- 1正常 0  冻结 -->
        <template slot="status" slot-scope="{row}">
          <el-tag v-if="row.status === 1" type="success" size="small">已支付</el-tag>
          <el-tag v-if="row.status === 0" type="danger" size="small">未支付</el-tag>
          <el-tag v-if="row.status === 3" type="warning" size="small">已退款</el-tag>
        </template>
        <template slot="if_fz" slot-scope="{row}">
          <el-tag v-if="row.if_fz === 1" type="warning" size="small">分账中</el-tag>
          <el-tag v-if="row.if_fz === 2" type="success" size="small">已分账</el-tag>
          <el-tag v-if="row.if_fz === 0" type="danger" size="small">否</el-tag>

        </template>
        <!-- 操作列 -->
        <template slot="action" slot-scope="{row}">
          <!--     <el-popconfirm
            class="ele-action"
            title="确定要释放订单吗？"
            @confirm="remove(row)">
            <el-link
              type="danger"
              slot="reference"
              :underline="false"
              icon="el-icon-delete"
              v-if="permission.includes('sys:order:delete')">释放
            </el-link>
          </el-popconfirm> -->
          <div :style="(row.status ==1 && row.pay_type ==1) ?'display: block':'display: none'">
     <!--       <el-popconfirm class="ele-action" title="确定要退款吗？" @confirm="refundOrder(row)">
              <el-link type="danger" slot="reference" :underline="false" v-if="permission.includes('sys:order:delete')">
                <el-button type="danger" size="mini">售后退款</el-button>
              </el-link>
            </el-popconfirm> -->
          </div>

        </template>
      </ele-pro-table>
    </el-card>
    <!-- 编辑弹窗 -->

  </div>
</template>

<script>
  import {
    mapGetters
  } from "vuex";


  export default {
    name: 'ExamUsercrad',

    computed: {
      ...mapGetters(["permission"]),
    },
    data() {
      return {
        // 表格数据接口
        url: '/CardcouponOrder/index',
        // 表格列配置
        columns: [

          {
            prop: 'mobile',
            label: '用户手机号',
            showOverflowTooltip: true,
            minWidth: 200,
            align: 'center',

          },


          {
            prop: 'name',
            label: '卡卷名称',
            showOverflowTooltip: true,
            minWidth: 200,
            align: 'center',
          },
          {
            prop: 'shichang',
            label: '时长',
            showOverflowTooltip: true,
            minWidth: 200,
            align: 'center',
          },
          {
            prop: 'num',
            label: '次数',
            showOverflowTooltip: true,
            minWidth: 200,
            align: 'center',
          },

          {
            prop: 'price',
            label: '价格',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center',
          },




          {
            prop: 'create_time',
            label: '下单时间',
            sortable: 'custom',
            showOverflowTooltip: true,
            minWidth: 160,
            align: 'center',
            formatter: (row, column, cellValue) => {
              return this.$util.toDateString(cellValue);
            }
          },
          {
            prop: 'status',
            label: '状态',
            align: 'center',
            width: 100,
            resizable: false,
            slot: 'status',
          },
          {
            prop: 'pay_time',
            label: '支付时间',
            showOverflowTooltip: true,
            minWidth: 200,
            align: 'center',
            formatter: (row, column, cellValue) => {
              return this.$util.toDateString(cellValue);
            }
          },
          {
            prop: 'order_on',
            label: '订单号',
            align: 'center',
            width: 250,
            resizable: false,

          },
          {
            prop: 'transaction_id',
            label: '支付单号',
            align: 'center',
            width: 250,
            resizable: false,

          },
          {
            prop: 'if_fz',
            label: '是否分账订单',
            align: 'center',
            width: 250,
            resizable: false,
            slot: 'if_fz',
          },

          {
            columnKey: 'action',
            label: '操作',
            width: 300,
            align: 'center',
            resizable: false,
            slot: 'action',

          }

        ],
        // 表格搜索条件
        where: {},
        // 表格选中数据
        selection: [],
        typeList: [],
        // 当前编辑数据
        current: null,
        // 是否显示编辑弹窗
        showEdit: false,
        showEdits: false,
      };
    },

    methods: {
      /* 刷新表格 */
      reload() {
        this.$refs.table.reload({
          where: this.where
        });
      },
      /* 重置搜索 */
      reset() {
        this.where = {};
        this.reload();
      },
      /* 显示编辑 */
      openEdit(row) {

        this.current = row;
        this.showEdit = true;
      },

      /* 显示编辑 */
      openEdits(row) {

        this.current = row;
        this.showEdits = true;
      },
      /* 删除 */
      remove(row) {
        const loading = this.$loading({
          lock: true
        });
        this.$http.post('/RechargeOrder/delete', {
          id: row.order_id
        }).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      },

      refundOrder(row) {
        const loading = this.$loading({
          lock: true
        });
        this.$http.post('/CardcouponOrder/refundOrder', {
          id: row.id
        }).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      },

      /* 批量删除 */
      removeBatch() {
        if (!this.selection.length) {
          this.$message.error('请至少选择一条数据');
          return;
        }
        this.$confirm('确定要删除选中的用户期限卡吗?', '提示', {
          type: 'warning'
        }).then(() => {
          const loading = this.$loading({
            lock: true
          });
          this.$http.post('/RechargeOrder/delete', {
            id: this.selection.map(d => d.id)
          }).then(res => {
            loading.close();
            if (res.data.code === 0) {
              this.$message.success(res.data.msg);
              this.reload();
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            loading.close();
            this.$message.error(e.message);
          });
        }).catch(() => {});
      },


    }
  }
</script>

<style scoped>
</style>
